package tech.runchen.gz5055.oms.modules.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import tech.runchen.gz5055.oms.common.utils.PageInfo;
import tech.runchen.gz5055.oms.common.utils.Query;
import tech.runchen.gz5055.oms.modules.system.entity.SysLogEntity;
import tech.runchen.gz5055.oms.modules.system.mapper.SysLogMapper;
import tech.runchen.gz5055.oms.modules.system.service.ISysLogService;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 * 系统日志 服务实现类
 * </p>
 *
 * @author zzj
 * @since 2023-03-02
 */
@Service
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLogEntity> implements ISysLogService {

    @Override
    public PageInfo queryPage(Map<String, Object> params) {

        String title = (String) params.get("title");
        Object businessType = params.get("businessType");
        Object operType = params.get("operType");
        Object status = params.get("status");


        IPage<SysLogEntity> page = this.page(
                new Query<SysLogEntity>().getPage(params),
                new QueryWrapper<SysLogEntity>()
                        .like(Objects.nonNull(title), "title", title)
                        .eq(Objects.nonNull(businessType), "business_type", businessType)
                        .eq(Objects.nonNull(operType), "oper_type", operType)
                        .eq(Objects.nonNull(status), "status", status)
                        .orderByDesc("id")
        );

        return new PageInfo(page);
    }

    @Override
    public List<SysLogEntity> querySelect(Map<String, Object> params) {

        String title = (String) params.get("title");
        Object businessType = params.get("businessType");
        Object operType = params.get("operType");
        Object status = params.get("status");

        List<SysLogEntity> list = this.list(new QueryWrapper<SysLogEntity>()
                .like(Objects.nonNull(title), "title", title)
                .eq(Objects.nonNull(businessType), "business_type", businessType)
                .eq(Objects.nonNull(operType), "oper_type", operType)
                .eq(Objects.nonNull(status), "status", status)
                .orderByDesc("id")
        );
        return list;
    }

    @Override
    public boolean saveSysLog(SysLogEntity sysLog) {
        return this.save(sysLog);
    }

    @Override
    public boolean updateSysLog(SysLogEntity sysLog) {
        return this.updateById(sysLog);
    }

    @Override
    public void deleteBatch(Long[] sysLogIds) {
        baseMapper.deleteBatchIds(Arrays.asList(sysLogIds));
    }

}
